{include file="common/header"/}
<div class="lemo-container">
    <div class="lemo-main">
            <fieldset class="layui-elem-field layui-field-title">
                <legend>领取记录{:lang('list')}</legend>
                <blockquote class="layui-elem-quote">
                    <div class="lemo-table">
                        <div class="layui-inline">
                            <input type="text" id='user_mobile' name="user_mobile" lay-verify="required"
                                   placeholder="{:lang('pleaseEnter')}手机号" autocomplete="off" class="layui-input">
                        </div>

                        <div class="layui-inline">
                            <input type="text" id='goods_name' name="goods_name" lay-verify="required"
                                   placeholder="{:lang('pleaseEnter')}权益名称" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-inline">
                            <div class="layui-form">
                                <div class="layui-input-inline">
                                    <select name="goods_status" lay-verify="required" lay-search id="goods_status">
                                        <option value="all">权益状态</option>
                                        <option value="1">已领取</option>
                                        <option value="2">已核销</option>
                                        <option value="3">用户删除</option>
                                        <option value="4">后台删除</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <a  href="javascript:;" class="layui-btn data-add-btn layui-btn-sm" lay-submit="" lay-filter="add" id="search">
                            {:lang('search')}
                        </a>
                        <a href="javascript:;" data-type="1" class="layui-btn layui-btn-sm layui-btn-danger" id="delAll">{:lang('delete checked')}</a>
                        <a href="javascript:;"  class="layui-btn data-add-btn layui-btn-sm" id="export">导出数据</a>
                    </div>
                </blockquote>

            </fieldset>

            <table class="layui-table" id="list" lay-filter="list"></table>
    </div>
</div>


<script type="text/html" id="action">
    <a data-href="{:url('edit')}?id={{d.id}}" class="layui-btn  layui-btn-xs" lay-event="edit">{:lang('edit')}</a>
    <a  class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">{:lang('del')}</a>
</script>


<script type="text/html" id="create_time">
    {{layui.util.toDateString(d.create_time*1000, 'yyyy-MM-dd HH:mm:ss')}}
</script>
<script type="text/html" id="end_time">
    {{layui.util.toDateString(d.end_time*1000, 'yyyy-MM-dd HH:mm:ss')}}
</script>
<!--<script type="text/html" id="update_time">-->
<!--    {{layui.util.toDateString(d.update_time*1000, 'yyyy-MM-dd HH:mm:ss')}}-->
<!--</script>-->

<script type="text/html" id="status">
    {{# if(d.status==1){ }}
    已领取
    {{# }else if( d.status==2){ }}
    已核销
    {{# }else if( d.status==3){ }}
    用户删除
    {{# }else{ }}
        后台删除
    {{# } }}
</script>

<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
<!--        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>-->
<!--        <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>-->
<!--        <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>-->
    </div>
</script>
{include file="common/footer"/}
<script>
    var tableIn = null;
    layui.config({
        base: "/static/admin/js/",
        version: true
    }).extend({
        Admin:'Admin',
    }).use(['table','Admin'], function () {
        var $ = layui.jquery,
            table = layui.table;

        tableIn = table.render({
            elem: '#list',
            id: 'exportTable',
            url: '{:url("index")}',
            method: 'post',
            title: '领取记录表',
            toolbar: '#toolbar', //开启头部工具栏，并为其绑定左侧模板

            defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                title: '提示'
                ,layEvent: 'LAYTABLE_TIPS'
                ,icon: 'layui-icon-tips' }],
            cols: [[
                {checkbox: true, fixed: true},
                {field: 'id', title: 'ID', width: 80, fixed: true, sort: true},
                {field: 'user_mobile', title: '手机号', width: 120, },
                {field: 'goods_name', title: '权益名称', width: 200},
                {field: 'status', title: '状态', width: 180, templet:'#status'},
                {field: 'create_time', title: '领取时间', width: 180,templet:'#create_time'},
                {field: 'end_time', title: '到期时间', width: 180,templet:'#end_time'},
                // {field: 'update_time', title: '更新时间', width: 180,templet:'#update_time'},
                // {title:'操作',width:150, toolbar: '#action',align:"center"},

            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true
        });
        //搜索
        $(document).on('click','#search',function(){
            var user_mobile = $('#user_mobile').val();
            var goods_name = $('#goods_name').val();
            var status = $('#goods_status').val();
            // if(!$keys){
            //     return layer.msg('请输入关键词');
            // }
            tableIn.reload({ page: {page: 1},where: {user_mobile: user_mobile, goods_name:goods_name, status:status}});

        });
        //导出所有数据事件
        $("#export").click(function(){
            //使用ajax请求获取所有数据
            var user_mobile = $('#user_mobile').val();
            var goods_name = $('#goods_name').val();
            var status = $('#goods_status').val();
            $.ajax({
                url: '{:url("export")}',
                type: 'post',
                data: {
                    type: 1,
                    user_mobile:user_mobile,
                    goods_name:goods_name,
                    status:status
                },
                async: false,
                dataType: 'json',
                success: function (res) {
                    //使用table.exportFile()导出数据
                    table.exportFile('exportTable', res.data, 'xlsx');
                }
            });
        })

    });

</script>